package org.spamforces.model;

import org.jacuzzi.mapping.Id;

import java.io.Serializable;

/**
 * @author alazarev
 */
public abstract class ApplicationEntity implements Serializable {
    @Id
    private long id;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public boolean isPersistent() {
        return id != 0;
    }

    public String toString() {
        return getClass().getName() + " {id=" + id + '}';
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof ApplicationEntity)) {
            return false;
        }

        ApplicationEntity entity = (ApplicationEntity) o;

        return id == entity.id;
    }

    public int hashCode() {
        if (id == 0) {
            return super.hashCode();
        } else {
            return (int) (id ^ (id >>> 32));
        }
    }
}
